public class StringConcatenateTest {
    public static void main(String[] args) {

        long startTime = System.currentTimeMillis();
        String result1 = null;
        for (int i = 0; i < 5000; i++) {
            result1 += "This is" + "testing the" + "difference" + "between" + "String" + "and" + "StringBuffer";
        }
        long endTime = System.currentTimeMillis();
        System.out.println("字符串连接" + " - 使用 + 操作符 : " + (endTime - startTime) + " ms");
        long startTime1 = System.currentTimeMillis();
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < 5000; i++) {
            result.append("This is");
            result.append("testing the");
            result.append("difference");
            result.append("between");
            result.append("String");
            result.append("and");
            result.append("StringBuffer");
        }
        long endTime1 = System.currentTimeMillis();
        System.out.println("字符串连接" + " - 使用 StringBuffer : " + (endTime1 - startTime1) + " ms");
    }
}
